#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>


int main()
{
  pid_t pid = fork();
  if (pid == -1)
  {
    perror("fork:");
    exit(1);
  }
  if (pid == 0)
  {
    printf("i am child process\n");
    sleep(5);
  }
  else 
  {
  int status;
  int ret;
  if ((ret = waitpid(-1, &status, 0)) == -1)
  {
    perror("wait");
    exit(1);
  }
  
  if (WIFEXITED(status) && ret == pid)
  {
    printf("exit code:%d\n", WEXITSTATUS(status));
  }
  }
  return 0;
}
